<?php 
	
	$key = current(array_keys($_POST));

	function checkUsername()
	{
		$username = $_POST['Username'];

	$paeg = "/^[a-z][a-z,0-9]{5,7}$/";

	$x = preg_match($paeg,$username);

	if (!$x) {
		$arr =array(
			'error'=>1,
			'info'=>' 用户名不合法，长度是以字母开头的6-8位的字母或数字'
			);
		echo json_encode($arr);
		exit;
	}

	$users = include_once './user.php';

	foreach ($users as $user) {
		if ($user['username']==$username) {
			$arr = array(
			'error'=>1,
			'info'=>' 用户名已存在'
			);
			echo json_encode($arr);
			exit;
		}
	}

	$arr = array(
			'error'=>0,
			'info'=>' 用户名合格'
		);

	echo json_encode($arr);
	exit;
	};

	function checkEmail()
	{
	$username = $_POST['Email'];

	$paeg = "/^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/";

	$x = preg_match($paeg,$username);

	if (!$x) {
		$arr =array(
			'error'=>1,
			'info'=>'邮箱格式错误'
			);
		echo json_encode($arr);
		exit;
	}

	// $users = include_once './user.php';

	// // foreach ($users as $user) {
	// // 	if ($user['username']==$username) {
	// // 		$arr = array(
	// // 		'error'=>1,
	// // 		'info'=>' 用户名已存在'
	// // 		);
	// // 		echo json_encode($arr);
	// // 		exit;
	// // 	}
	// // }

	$arr = array(
			'error'=>0,
			'info'=>' 邮箱可用'
		);

	echo json_encode($arr);
	exit;
	};

	function checkPassword()
	{
	$username = $_POST['Password'];

	$paeg = "/^\w{6,13}$/";

	$x = preg_match($paeg,$username);

	if (!$x) {
		$arr =array(
			'error'=>1,
			'info'=>'密码长度不符合，最少6位'
			);
		echo json_encode($arr);
		exit;
	}

	$arr = array(
			'error'=>0,
			'info'=>' 密码可用'
		);

	echo json_encode($arr);
	exit;
	};

	function checkother()
	{
	$arr = array(
			'error'=>2,
			'info'=>' 传的参数不对'
		);

	echo json_encode($arr);
	exit;
	};

	switch ($key) {
		case 'Username':
			checkUsername();
			break;
		
		case 'Email':
			checkEmail();
			break;

		case 'Password':
			checkPassword();
			break;

		default:
			checkother();
			break;
	}


 ?>